//
//  CooperationTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "CooperationTableViewCell.h"

@interface CooperationTableViewCell()

@property (nonatomic,strong) UIView *titleView;
@property (nonatomic,strong) UIView *infoView;

@property (nonatomic,strong) UILabel *titleLabel;

@end

@implementation CooperationTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        self.separatorInset = UIEdgeInsetsZero;
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            self.layoutMargins = UIEdgeInsetsZero;
        }
        
        _titleView = [UIView new];
        _titleView.backgroundColor = [UIColor whiteColor];
        
        _infoView = [UIView new];
        _infoView.backgroundColor = [UIColor whiteColor];
        
        _titleLabel = [UILabel new];
        _titleLabel.font = DEF_FontSize_14;
        
        NSMutableAttributedString *attStr = [NSMutableAttributedString new];
        NSTextAttachment *imgAtt = [NSTextAttachment new];
        imgAtt.image = [UIImage imageNamed:@"togeter"];
        imgAtt.bounds = CGRectMake(0, -2, 15, 15);
        [attStr appendAttributedString:[NSAttributedString attributedStringWithAttachment:imgAtt]];
        [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@" 选择合作"]];
        _titleLabel.attributedText = attStr;
        
        self.contentView.backgroundColor = getColor(@"f1f2f6");
        [self.contentView addSubview:_titleView];
        [self.contentView addSubview:_infoView];
        [_titleView addSubview:_titleLabel];
        
        NSArray *titleArray = @[@"仅代工",@"仅贴牌",@"贴牌投标"];
        for (int i = 0; i<titleArray.count; i++) {
            UILabel *label = [[UILabel alloc] init];
            label.font = DEF_FontSize_11;
            label.text = titleArray[i];
            label.tag = 100+i;
            
            UIButton *btn = [[UIButton alloc] init];
            btn.tag = 200+i;
            [btn setImage:[UIImage imageNamed:@"duihao"] forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:@"duihaofu"] forState:UIControlStateSelected];
            [btn addTarget:self action:@selector(selectEvent:) forControlEvents:UIControlEventTouchUpInside];
            [_infoView addSubview:label];
            [_infoView addSubview:btn];
        }
    }
    return self;
}

- (void)selectEvent:(UIButton *)sender{
    for (int i = 0; i<3; i++) {
        UIButton *btn = [self.contentView viewWithTag:i+200];
        if (btn != sender) {
            btn.selected = NO;
        }else{
            sender.selected = !sender.selected;
            if (self.selectHandle) {
                self.selectHandle(i);
            }
        }
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _titleView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 27);
    _infoView.frame = CGRectMake(0, 32, SCREEN_WIDTH, self.frame.size.height-32);
    _titleLabel.frame = CGRectMake(10, 0, SCREEN_WIDTH-20, 27);
    
    CGFloat height = _infoView.frame.size.height/3.;
    for (int i = 0; i<3; i++) {
        UILabel *label = [self.contentView viewWithTag:i+100];
        label.frame = CGRectMake(10, i*height, 100, height);
        
        UIButton *btn = [self.contentView viewWithTag:i+200];
        btn.frame = CGRectMake(SCREEN_WIDTH-30, 0, 20, 20);
        btn.center = CGPointMake(btn.center.x, label.center.y);
    }
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;

}

@end
